<?php

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

require_once libfile('function/core');
require_once libfile('function/date');
require_once libfile('function/database');
require_once libfile('function/vote');

if($operation == 'create') {
	list($img_start_days, $activities) = get_activities();
	$sql = 'select img_start_day from '.DB::table('vote_activity').' where img_start_day in ('.dimplode($img_start_days).')';
	list($img_start_day_exists, $rows) = query($sql, 'img_start_day');
	for ($i = count($activities) - 1; $i >= 0; $i-- ) {
		$activitie = $activities[$i];

		if (in_array($activitie['value'], $img_start_day_exists)){
			unset($activities[$i]);
		}
	}
	include_once template("bid/admin_create");
} else if($operation == 'c_submit') {
	$activities = array();
	$start_day_list = getgpc('start_days');
	foreach ($start_day_list as $start_day){
		$id = DB::insert('vote_activity', create_activity($start_day), true);
		DB::insert('vote_activity_count', array('id' => $id));
	}

	showmessage(lang('bid/template', 'create_activity_success'), 'admin.php?action=vote&operation=list', array(), array('alert' => 'right') );

} else if($operation == 'list') {
	$today = to_days();
	$sql = 'select * from '.DB::table('vote_activity').' where bid_start_day > '.$today.' order by bid_start_day limit 20';
	$activities = query($sql);
	format_activities($activities);

	include_once template("bid/admin_list");
	
} else if($operation == 'e_submit') {
	
	
} else if($operation == 'edit') {
	$id = getgpc('id');

	$sql = 'select * from '.DB::table('vote_activity').' where id = '.$id.' order by update_time desc limit 20';
	$activity = DB::fetch_first($sql);

	$years = get_years(date('Y'), 1, 1);
	$months = get_months();
	$days = get_days();
	list($img_start_year, $img_start_month, $img_start_day) = get_year_month_day( date('Y-m-d', $activity['img_start_day']) );
	list($img_end_year, $img_end_month, $img_end_day) = get_year_month_day( date('Y-m-d', $activity['img_end_day']) );
	list($bid_start_year, $bid_start_month, $bid_start_day) = get_year_month_day( date('Y-m-d', $activity['bid_start_day']) );
	list($bid_end_year, $bid_end_month, $bid_end_day) = get_year_month_day( date('Y-m-d', $activity['bid_end_day']) );

	include_once template("bid/admin_edit");
}
?>